package view;

import java.awt.Dimension;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controller.CreateKundeAction;
import db.Kunde;
import db.KundeHibernateImpl;

public class CreateView extends JPanel{

	private CreateKundeAction action;
	private JTextField  field;
	public CreateView(){
		super();
		setBorder(BorderFactory.createTitledBorder("Kunde anlegen"));
		action = new CreateKundeAction();

		field = new JTextField();
		field.setPreferredSize(new Dimension(100,25));
		add(field);
		add(new JButton(new AbstractAction("Anlegen") {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				//Hier ne Factory oder Sosntiges benutzen
				Kunde k = new KundeHibernateImpl();
				k.setName(field.getText());
				action.setNewKunde(k);
				action.execute();
				field.setText("");
			}
		}));
	}
}
